package com.example.lbs.config;

import com.example.lbs.model.Shop;
import com.example.lbs.service.ShopGeoService;
import com.example.lbs.service.ShopService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class StartupSync implements ApplicationRunner {

    private final ShopService shopService;
    private final ShopGeoService geoService;

    public StartupSync(ShopService shopService, ShopGeoService geoService) {
        this.shopService = shopService;
        this.geoService = geoService;
    }

    @Override
    public void run(ApplicationArguments args) {
        List<Shop> all = shopService.listAll();
        if (all == null || all.isEmpty()) return;
        for (Shop s : all) {
            if (s.getLng() != null && s.getLat() != null) {
                geoService.addShopGeo(s.getId(), s.getLng(), s.getLat(), s.getBrand());
            }
        }
    }
}